package com.boboPlanet.user.controller;

import com.boboPlanet.comm.constance.CommInstance;
import com.boboPlanet.comm.entity.dto.LoginUserInfoDTO;
import com.boboPlanet.comm.result.ResponseResult;
import com.boboPlanet.user.annotation.LimitPass;
import com.boboPlanet.user.entity.dto.ArticleMainDTO;
import com.boboPlanet.user.entity.dto.UpdateUserInfoDTO;
import com.boboPlanet.user.entity.vo.CurrentUserInfoVO;
import com.boboPlanet.user.entity.vo.UserArtMainVO;
import com.boboPlanet.user.service.UserOperationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2023/2/14
 **/
@RestController
@RequestMapping("/userOperation")
@Api(value = "用户业务操作",tags = "用户业务操作")
public class UserController {

    @Resource
    private UserOperationService userOperationService;


    @PostMapping("/planetLogin")
    @ApiOperation("用户登录")
    @LimitPass
    public ResponseResult<Object> planetLogin(@RequestBody LoginUserInfoDTO dto){
        return userOperationService.planetLogin(dto);
    }

    @PostMapping("/planetRegister")
    @ApiOperation("用户注册")
    @LimitPass
    public ResponseResult<Boolean> planetRegister(@RequestBody LoginUserInfoDTO dto){
        return userOperationService.planetRegister(dto);
    }

    @GetMapping("/planetUserLogout")
    @ApiOperation("退出登录")
    @LimitPass
    public ResponseResult<Boolean> planetUserLogout(String account,HttpServletRequest request){
        String token = request.getHeader(CommInstance.TOKEN_AUTHORIZATION);
        return ResponseResult.isSuccess(userOperationService.planetUserLogout(account,token));
    }

    @PostMapping("/updatePlanetUserInfo")
    @ApiOperation("修改用户信息")
    public ResponseResult<Boolean> updatePlanetUserInfo(@Validated @RequestBody UpdateUserInfoDTO dto){
        return userOperationService.updatePlanetUserInfo(dto);
    }

    @GetMapping("/getCurrentUserInfo")
    @ApiOperation("获取当前用户信息")
    public ResponseResult<CurrentUserInfoVO> getCurrentUserInfo(@RequestParam String account,HttpServletRequest request){
        String token = request.getHeader(CommInstance.TOKEN_AUTHORIZATION);
        return ResponseResult.isSuccess(userOperationService.getCurrentUserInfo(account,token));
    }

    @PostMapping("/updateUserAvatar")
    @ApiOperation("spring-x-file-storage 上传头像")
    public ResponseResult<String> updateUserAvatar(@RequestParam("file") MultipartFile file,@RequestParam("fileType") String fileType,
                                                    HttpServletRequest request){
        String token = request.getHeader(CommInstance.TOKEN_AUTHORIZATION);

        return userOperationService.updateUserAvatar(file,fileType,token);

    }

    @PostMapping("/getUserArtList")
    @ApiOperation("获取当前用户文章列表")
    public ResponseResult<UserArtMainVO> getUserArtList(@RequestBody ArticleMainDTO mainDTO){
        return ResponseResult.isSuccess(userOperationService.getUserArtList(mainDTO));
    }



}
